package com.zhugang.week04;

import java.util.HashMap;
import java.util.Map;

/**
 * @program algorithms
 * @description: climbStairs
 * @author: chanzhugang
 * @create: 2022/06/15 19:20
 */
public class ClimbStairs2 {

    private final Map<Integer, Integer> cacheMap = new HashMap<>();

    public int climbStairs(int n) {
        if (n <= 2) {
            return n;
        }
        if (cacheMap.containsKey(n)) {
            return cacheMap.get(n);
        }
        int res = climbStairs(n - 1) + climbStairs(n - 2);
        cacheMap.put(n, res);
        return res;
    }
}